package com.darren.archive.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.darren.framework.entity.BaseEntity;
import com.darren.framework.utils.Constant;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.ResultCheckStyle;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = Constant.TABLE_NAME_PREV + "users", uniqueConstraints = {@UniqueConstraint(columnNames = "account")})
@SQLDelete(sql = "update " + Constant.TABLE_NAME_PREV + "users set is_delete = true,version=version+1 where id=? and version=?", check = ResultCheckStyle.COUNT)
@Where(clause = " is_delete  = false or is_editable = false ")
public class SysUser extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 6816867491719633601L;

    /**
     * 用户帐号，最大长度50个字符
     */
    @Column(name = "account", columnDefinition = "varchar(50) NOT NULL comment '用户帐号，最大长度50个字符'")
    private String userAccount;

    /**
     * 用户密码，最大长度100个字符,
     * 密码字段不序列化到Json字符串中
     * 密码字段只初始化插入，不随用户信息更新；需要单独方法更改密码
     */
    @JSONField(serialize = false)
    @Column(name = "password", updatable = false, columnDefinition = "varchar(100) NOT NULL default '' comment '用户密码，最大长度100个字符'")
    private String password;

    /**
     * 姓名，最大长度30个字符
     */
    @Column(name = "name", columnDefinition = "varchar(30) default '' comment '姓名，最大长度30个字符'")
    private String name;

    /**
     * 昵称，最大长度30个字符
     */
    @Column(name = "nickname", columnDefinition = "varchar(30) default '' comment '昵称，最大长度30个字符'")
    private String nickname;

    /**
     * 头像文件
     */
    @Column(name = "photo", updatable = false, columnDefinition = "varchar(128) default '' comment '用户头像，最大长度128个字符'")
    private String photo;


    /**
     * 年龄
     */
    @Column(name = "age", columnDefinition = "int default 0 comment '年龄'")
    private Integer age;

    /**
     * 性别
     */
    @Column(name = "gender", columnDefinition = "varchar(5) default '' comment '性别'")
    private String gender;

    /**
     * 生日
     */
    @JSONField(name = "birthday", format = "yyyy-MM-dd")
    @Column(name = "birthday", columnDefinition = "datetime default NULL comment '生日'")
    private Date birthday;

    /**
     * 手机号码
     */
    @Column(name = "mobile", columnDefinition = "varchar(20) default '' comment '手机号码'")
    private String mobile;

    /**
     * 邮箱
     */
    @Column(name = "email", columnDefinition = "varchar(60) default '' comment '邮箱'")
    private String email;

    @ElementCollection(fetch = FetchType.EAGER)
    @JoinTable(name = "d_emails", joinColumns = @JoinColumn(name = "id"))
//	@Column(name = "emails")
    private List<String> emails = new ArrayList<String>();

    /**
     * 微信
     */
    @Column(name = "wechat", columnDefinition = "varchar(150) default '' comment '微信'")
    private String wechat;


    /**
     * 部门  id，引用部门表的id字段
     */
    @ApiModelProperty(notes = "部门  id，引用部门表的id字段")
    @Column(name = "department_id", columnDefinition = "bigint  default -1 comment '部门  id，引用部门表的id字段'")
    private Long departmentId;

    /**
     * 是否允许编辑 true：可编辑，false：不可编辑。内置的用户不允许编辑,不允许查看
     */
    @ApiModelProperty(notes = "是否允许编辑 true：可编辑，false：不可编辑。内置的用户不允许编辑")
    @Column(name = "is_editable", columnDefinition = "tinyint default 0 comment '是否允许编辑 1：可编辑，0：不可编辑。内置的用户不允许编辑'")
    private boolean editable = true;

    /**
     * 用户状态，是否启用：true 启用；false 禁用
     */
    @ApiModelProperty(notes = " 用户状态，是否启用：true 启用；false 禁用")
    @Column(name = "is_enable", columnDefinition = "tinyint default 0 comment '用户状态，是否启用：1 启用；0 禁用'")
    private boolean enable = false;

    public String getUserAccount() {
        return userAccount;
    }

    public void setUserAccount(String userAccount) {
        this.userAccount = userAccount;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<String> getEmails() {
        return emails;
    }

    public void setEmails(List<String> emails) {
        this.emails = emails;
    }

    public String getWechat() {
        return wechat;
    }

    public void setWechat(String wechat) {
        this.wechat = wechat;
    }

    public boolean isEditable() {
        return editable;
    }

    public Long getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Long departmentId) {
        this.departmentId = departmentId;
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
    }

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }
}
